#include  <cstdio>

int main(int argc, char *argv[])
{
	char s[20];
	scanf("%s",s);
	int sum = 0;
	int non;
	for( int i = 0 ; i < 10 ; ++i )
	{
		if(s[i] == '?')
			non = i;
		else if (s[i] == 'X')
			sum += 10;
		else
			sum += (s[i]-'0') * (10 - i);
	}
	int total = non == 9 ? 10 : 9;
	for( int i = 0; i <= total ; ++i )
	{
		if( (sum + i*(10-non)) % 11 == 0)
		{
			if(i == 10)
			{
				printf("X\n");
				return 0;
			}
			printf("%d\n",i);
			return 0;
		}
	}
	printf("-1\n");
}

